package 消失的两个数字;

class Solution {
    public int[] missingTwo(int[] nums) {
        int tmp = 0;
        int[] ret = new int[2];
        for(int x: nums){
            tmp ^= x;
        }
        for(int i = 1; i <= nums.length + 2; i++){
            tmp ^= i;
        }
        int diff = 0;
        while(true){
            if(((tmp >> diff) & 1) == 1){
                break;
            }else{
                diff++;
            }
        }
        for(int x:nums){
            if(((x >> diff) & 1) == 1){
                ret[0] ^= x;
            }else{
                ret[1] ^= x;
            }
        }
        for(int i = 1; i <= nums.length + 2; i++){
            if(((i >> diff) & 1) == 1){
                ret[0] ^= i;
            }else{
                ret[1] ^= i;
            }
        }
        return ret;
    }
}